
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>用户管理</h5>
                <div class="ibox-tools">

                </div>
            </div>
            <div class="ibox-content">

                <div class="filter-box">

                </div>
                <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog"  aria-hidden="true">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                <h4 class="modal-title">回复咨询</h4>
                                <!--<small class="font-bold">这里可以显示副标题。-->
                            </div>
                            <div class="modal-body">
                                <form id="js-comment-form" method="post"  class="form-horizontal" enctype="multipart/form-data">
                                    <input type="hidden" name="consult_id" readonly  id="js-comment-consult_id">
                                    <input type="hidden" name="admin_user_id" value="89757" readonly  id="s-comment-admin">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">咨询标题：</label>
                                        <div class="col-sm-9">
                                            <span id="js-title"></span>
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">咨询人：</label>
                                        <div class="col-sm-9">
                                            <span id="js-username"></span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">咨询类型：</label>
                                        <div class="col-sm-9">
                                            <span id="js-type"></span>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">活动介绍：</label>
                                        <div class="col-sm-9">
                                            <textarea class="form-control" id="js-comment-content" name="content"  rows="10" cols="80"></textarea>
                                        </div>
                                    </div>


                                </form>
                            </div>

                            <div class="modal-footer">
                                <button type="button" id="js-close-model" class="btn btn-sm btn-white" data-dismiss="modal">关闭</button>
                                <button type="button" onclick="comment()" class="btn btn-sm btn-primary">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="jqGrid_wrapper">
                    <table id="table_list_1"></table>
                    <div id="pager_list_1"></div>
                </div>

            </div>
        </div>
    </div>

    <button id="js-btn-openModal" style="position: absolute;z-index: -2;right: -200px;visibility: hidden" data-toggle="modal" data-target="#myModal6">打开回复的model</button>

</div>



<!-- 自定义js -->
<script src="/static/js/content.js?v=1.0.0"></script>


<script>


    $(document).ready(function () {

        $.jgrid.defaults.styleUI = 'Bootstrap';
        // Examle data for jqGrid


        $("#table_list_1").jqGrid({
            datatype: "json", //将这里改为使用JSON数据
            url:'filter', //这是Action的请求地址
            mtype: 'POST',
            jsonReader: {
                root:"data.data", page:"data.current_page", total:"data.last_page",records:"data.total", repeatitems:true,id :"id"
            },
            // data: mydata,
            // datatype: "local",
            height: 550,
            autowidth: true,
            shrinkToFit: true,
            rowNum: 20,
            // rowList: [10, 20, 30],

            cellEdit : true,
            cellsubmit:'remote',
            cellurl:'edit_manager',
            editurl:'add',

            colNames: ['编号','用户名','密码','用户组','真实姓名', '邮箱 ',' 最后登录时间','操作'],
            colModel: [
                {name: 'id', index: 'id', width: 50,search: true},
                {name: 'username', index: 'username', width: 100,search: true,editable:true},
                {name: 'password', index: 'password', width: 100,search: true,editable:true, formatter: function (value, grid, rows, state) {
                        var Str = "*********";
                        return Str;
                    }},
                {name: 'group', index: 'group', width: 100,search: true,edittype:'select',editable:true,editoptions:{
            value:getGroupList()}},
                {name: 'real_name', index: 'real_name', width: 50,search: true,editable:true,},
                {name: 'email', index: 'email', width: 100,search: true,editable:true,},
                {name: 'last_login_time', index: 'last_login_time', width: 60,search: true},
                {
                    width: 100,
                    name:'id',
                    formatter: function (value, grid, rows, state) {
                            var Str = "<a href='/consult/detail?id="+value+"' class=\"btn btn-primary btn-sm  m-r-sm\"  >修改</a>"+"<div class=\"btn btn-primary btn-sm m-r-sm\" onclick=\"replay('"+rows.id+'\',\''+rows.title+'\',\''+rows.is_fee+'\',\''+rows.user_open_id+"')\" >删除</div>";
                        return Str;
                    }
                }



            ],
            pager: "#pager_list_1",
            viewrecords: true,

            hidegrid: false,

        });

        // Add selection
        $("#table_list_1").setSelection(4, true);

        // Setup buttons
        $("#table_list_1").jqGrid('navGrid', '#pager_list_1', {
            closeAfterAdd:true,
            // edit: true,
            // edittext:'新增',
            // editfunc:function(id){
            //     var  rowsList = getSelecteds();
            //     if(!rowsList){
            //         alert('已经审核的数据，无法再次审核');
            //         return;
            //     }
            //     $.post('flag',{'rows':rowsList,action:'open'},function(res){
            //         console.log(res)
            //         if(res.code==100){
            //             parent.layer.msg('批量开启成功');
            //             $("#table_list_1").trigger("reloadGrid");
            //         }
            //
            //     })
            //     console.log(rowsList)
            //     // var rows = $("#table_list_1").jqGrid('getRowData', id);
            //
            // },
            // add: false,
            // del: false,
            // delfunc:function(id){
            //
            //     var  rowsList = getSelecteds();
            //
            //     $.post('flag',{'rows':rowsList,action:'close'},function(res){
            //         console.log(res)
            //         if(res.code==100){
            //             parent.layer.msg('批量关闭成功');
            //             $("#table_list_1").trigger("reloadGrid");
            //         }
            //
            //     })
            //     console.log(rowsList)
            //     // var rows = $("#table_list_1").jqGrid('getRowData', id);
            //
            // },
            // deltext:'关闭',
            search: false
        }, {
            height: 200,
            reloadAfterSubmit: true
        });

        // Add responsive to jqGrid
        $(window).bind('resize', function () {
            var width = $('.jqGrid_wrapper').width();
            $('#table_list_1').setGridWidth(width);
        });
    });



    function getSelecteds(){
//获取多选到的id集合
        var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow");
//遍历访问这个集合
        var tempArr=[];
        $(ids).each(function (index, id){
            //由id获得对应数据行
            var row = $("#table_list_1").jqGrid('getRowData', id);

            tempArr.push({id:row.id,check:row.check})
        })

        return tempArr;
    }


    function getGroupList(){
        var data=null;
        $.ajax({
            method:'get',
            async:false,
            url:'/rule/rule_group_all',
            success:function(e){
                data=e.data
            }
        })

        return data;
    }

</script>

<script>

    function replay(id,title,is_fee,user_open_id) {
        console.log(id,title,is_fee,user_open_id)
        $('#js-comment-consult_id').val(id)
        $('#js-title').html(title)
        $('#js-username').html(user_open_id)
        if(is_fee==1){
            $('#js-type').html('专属咨询')
        }else{
            $('#js-type').html('普通咨询')
        }

        //唤起modal
        $('#js-btn-openModal').click()
    }

    function comment() {
        var commentData = $('#js-comment-form').serialize();

        $.post('/consult/replay',commentData,function(res){
            console.log(res)
            if(res.code ==100){
                $('#js-close-model').click();
                document.getElementById('js-comment-form').reset();
                $("#table_list_1").trigger("reloadGrid");
            }
        })
    }
    // filterFun()
    function filterFun() {
        // var filterForm = document.getElementById('filter-form');
        // var filterData = new FormData(filterForm);
        //
        var filterData = $('#filter-form').serializeArray()
        console.log(filterData,$("#table_list_1"));
        //传入查询条件参数
        $("#table_list_1").jqGrid("setGridParam",{postData:filterData}).trigger("reloadGrid");
        //每次提出新的查询都转到第一页
        // $("#jqgridTable").jqGrid("setGridParam",{page:1}).;
        //提交post并刷新表格
        // $("#jqgridTable").jqGrid("setGridParam",{'url':'filter'}).trigger("reloadGrid");


        // $.post('filter',filterData,function (res) {
        //     console.log(res);
        //
        //
        //     $('#table_list_1').jqGrid('clearGridData');  //清空表格
        //     $('#table_list_1').jqGrid('setGridParam',{  // 重新加载数据
        //         datatype:'local',
        //         data : res.data,   //  newdata 是符合格式要求的需要重新加载的数据
        //         page:1
        //     }).trigger("reloadGrid");
        //
        //
        // })

    }
</script>

